package com.boot.system.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.framework.constants.PageConstants;
import com.boot.system.dto.SysParamsDTO;
import com.boot.system.entity.SysParamsEntity;
import com.boot.system.mapper.SysParamsMapper;
import com.boot.system.wrapper.SysParamsWrapper;
import com.boot.system.service.ISysParamsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author yangfan
 * @date 2024/2/6
 * @Description
 */
@Service
public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParamsEntity> implements ISysParamsService {

    private QueryWrapper<SysParamsEntity> getQueryWrapper(Map<String, Object> params) {
        QueryWrapper<SysParamsEntity> wrapper = new QueryWrapper<>();
        return wrapper;
    }

    private Page<SysParamsEntity> getPage(Map<String, Object> params) {
        long pageNum = Long.parseLong(String.valueOf(params.get(PageConstants.PAGE)));
        long pageSize = Long.parseLong(String.valueOf(params.get(PageConstants.LIMIT)));
        return new Page<>(pageNum, pageSize);
    }

    @Override
    public IPage<SysParamsDTO> selectPage(Map<String, Object> params) {
        return SysParamsWrapper.build().pageDTO(baseMapper.selectPage(getPage(params), getQueryWrapper(params)));
    }

    @Override
    public List<SysParamsDTO> selectList(Map<String, Object> params) {
        return SysParamsWrapper.build().listDTO(baseMapper.selectList(getQueryWrapper(params)));
    }
}
